/**
 * $Id: Employee.java 84 2012-12-20 17:19:18Z Denis.Skalsky@gmail.com $
 */
package com.globallogic.skalskyy.javabasic.valstaff;

/**
 * Employee stores common information.
 * @author $Author: Denis.Skalsky@gmail.com $
 * @version $Revision: 84 $
 */
abstract public class Employee {
	
	/** Employee's id */
	private Field<Integer> id = new Field<Integer>(-1);
	
	/** Employee's first name */
	private Field<String> firstName = new Field<String>();
	
	/** Employee's second name */
	private Field<String> secondName = new Field<String>();
	
	/** Employee's position */
	private Field<String> position = new Field<String>();
	
	/** Employee's date of birth */
	private Field<String> dateOfBirth = new Field<String>();
			
	/** Template to format toString() output */
	private static final String TO_STRING_TEMPLATE = "%s %s, %s";
	
	@Override
	public String toString() {
		return String.format(
				Employee.TO_STRING_TEMPLATE,
				getFirstName(), 
				getSecondName(), 
				getPosition());
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dateOfBirth == null) ? 0 : dateOfBirth.hashCode());
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((position == null) ? 0 : position.hashCode());
		result = prime * result
				+ ((secondName == null) ? 0 : secondName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		
		if (obj == null)
			return false;
		
		if (getClass() != obj.getClass())
			return false;
		
		Employee other = (Employee) obj;
		
		if (dateOfBirth == null) {
			if (other.dateOfBirth != null)
				return false;
		} else if (!dateOfBirth.equals(other.dateOfBirth))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (position == null) {
			if (other.position != null)
				return false;
		} else if (!position.equals(other.position))
			return false;
		if (secondName == null) {
			if (other.secondName != null)
				return false;
		} else if (!secondName.equals(other.secondName))
			return false;
		return true;
	}

	public String getFirstName() {
		return firstName.getValue();
	}

	public void setFirstName(String firstName) {
		this.firstName.setValue(firstName);
	}

	public String getDateOfBirth() {
		return dateOfBirth.getValue();
	}

	public void setDateOfBirth(String dateOfBirth) {
		this.dateOfBirth.setValue(dateOfBirth);
	}

	public String getSecondName() {
		return secondName.getValue();
	}

	public void setSecondName(String secondName) {
		this.secondName.setValue(secondName);
	}

	public String getPosition() {
		return position.getValue();
	}

	public void setPosition(String position) {
		this.position.setValue(position);
	}
		
	/**
	 * Check first name for a match ignoring case
	 * @param firstName first name for checking 
	 * @return true if matches else false
	 */ 
	public boolean compareFirstName(String firstName) {
		return this.firstName.equals(new Field<String>(firstName));
	}

	/**
	 * Check second name for a match ignoring case
	 * @param secondName first name for checking 
	 * @return true if matches else false
	 */ 
	public boolean compareSecondName(String secondName) {
		return this.secondName.equals(new Field<String>(secondName));
	}	
	
	/**
	 * Check position for a match ignoring case
	 * @param position position for checking 
	 * @return true if matches else false
	 */ 
	public boolean comparePosition(String position) {
		return this.position.equals(new Field<String>(position));
	}
	
	/**
	 * Check date of birth for a match ignoring case
	 * @param dateOfBirth date of birth for checking 
	 * @return true if matches else false
	 */ 
	public boolean compareDateOfBirth(String date) {
		return this.dateOfBirth.equals(new Field<String>(date));
	}

	public int getId() {
		return id.getValue();
	}

	protected void setId(int id) {
		this.id.setValue(id);
	}
}